package scheduler.devices;

import java.util.concurrent.atomic.AtomicInteger;

public final class SharedMemory { // final marks this class as not extendable
	
	public static AtomicInteger IOMutex; // mutex
	public static AtomicInteger producerMutex; // mutex
	public static AtomicInteger consumerMutex; // mutex
	
	public static AtomicInteger cp_full; // counting semaphore
	public static AtomicInteger cp_empty; // counting semaphore
	
	private static SharedMemory sharedMem; // instance of self
	
	private static final int BUFFER_SIZE = 100;

	// private constructor ensured that there can only be 
	//one instance of SharedMemory follows the singleton design pattern
	private SharedMemory() {
		IOMutex = new AtomicInteger(1);
		producerMutex = new AtomicInteger(1);
		consumerMutex = new AtomicInteger(1);
		cp_full = new AtomicInteger(0);
		cp_empty = new AtomicInteger(BUFFER_SIZE);
	}
	
	public static SharedMemory instance() {
		
		if (sharedMem == null)
			return new SharedMemory();
		else 
			return sharedMem;
	}
}
